using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Parry_Skill : Skill
{
    [Header("Parry")]
    [SerializeField] private UI_SkillTreeSlot parryUnlockButton; // 格挡技能解锁按钮
    public bool parryUnlocked { get; private set; } // 格挡技能是否解锁

    [Header("Parry restore")]
    [SerializeField] private UI_SkillTreeSlot restoreUnlockButton; // 格挡恢复技能解锁按钮
    public bool restoreUnlocked { get; private set; } // 格挡恢复技能是否解锁
    [Range(0f, 1f)]
    [SerializeField] private float restoreHealthPerentage; // 恢复的生命值百分比

    [Header("Parry with mirage")]
    [SerializeField] private UI_SkillTreeSlot parryWithMirageUnlockButton; // 格挡时释放幻影技能解锁按钮
    public bool parryWithMirageUnlocked { get; private set; } // 格挡时释放幻影技能是否解锁

    // 重写UseSkill方法
    public override void UseSkill()
    {
        base.UseSkill();
        if (restoreUnlocked)
        {
            // 计算恢复的生命值并增加到玩家的生命值中
            int restoreAmount = Mathf.RoundToInt(player.stats.GetMaxHealthValue() * restoreHealthPerentage);
            player.stats.IncreaseHealthBy(restoreAmount);
        }
    }

    // 重写Start方法
    protected override void Start()
    {
        base.Start();
        // 为解锁按钮添加点击事件监听器
        parryUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockParry);
        restoreUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockParryRestore);
        parryWithMirageUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockParryWithMirage);
    }

    protected override void CheckUnlock()
    {
        UnlockParry();
        UnlockParryRestore();
        UnlockParryWithMirage();
    }

    // 解锁格挡技能
    public void UnlockParry()
    {
        if (parryUnlockButton.unlocked)
            parryUnlocked = true; // 设置格挡技能已解锁
    }

    // 解锁格挡恢复技能
    public void UnlockParryRestore()
    {
        if (restoreUnlockButton.unlocked)
            restoreUnlocked = true; // 设置格挡恢复技能已解锁
    }

    // 解锁格挡时释放幻影技能
    public void UnlockParryWithMirage()
    {
        if (parryWithMirageUnlockButton.unlocked)
            parryWithMirageUnlocked = true; // 设置格挡时释放幻影技能已解锁
    }

    // 格挡时释放幻影
    public void MakeMirageOnParry(Transform _respawnTransform)
    {
        if (parryWithMirageUnlocked)
        {
            SkillManager.instance.clone.CreateCloneWithDelay(_respawnTransform); // 创建带有延迟的幻影
        }
    }
}